#include <bits/stdc++.h>

#define in read()
#define fi first
#define se second
#define pb push_back
#define y1 y_alpha_1

using namespace std;

using ll = long long;
using db = double;
using vec = vector<int>;
using pii = pair<int,int>;

int read() {
	int x = 0; bool f = 0; char ch = getchar();
	while(!isdigit(ch)) f |= ch == '-',ch = getchar();
	while(isdigit(ch)) x = (x << 1) + (x << 3) + (ch ^ 48),ch = getchar();
	return f ? -x : x;
}

const int N = 5e3 + 10;
const int M = 1e5 + 10;

int n,Q;

struct triangle { int x,y,dir,l; } dot[M];
int ans[M];

struct BIT {
	int arr[N << 1][N];
	void clear() { memset(arr,0,sizeof arr); }
	void add(int x,int y,int v = 1) {
		for(int i = x;i <= n << 1;i += i & -i)
			for(int j = y;j <= n;j += j & -j)
				arr[i][j] += v;
	}
	int query(int x,int y) {
		int res = 0;
		for(int i = x;i;i -= i & -i)
			for(int j = y;j;j -= j & -j)
				res += arr[i][j];
		return res;
	}
}T;

int main() {
#ifndef ONLINE_JUDGE
	freopen("1.in","r",stdin);
#endif
	n = in,Q = in;
	for(int i = 1;i <= Q;i++) {
		int op = in;
		if(op == 1) {
			dot[i].dir = in; dot[i].x = in; dot[i].y = in; dot[i].l = in;
		} else {
			dot[i].x = in; dot[i].y = in;
		}
	}
	for(int i = 1;i <= Q;i++) {
		if(dot[i].dir == 1) T.add(dot[i].x,dot[i].y,1),
								T.add(dot[i].x,dot[i].y + dot[i].l + 1,-1);
		if(dot[i].dir == 2) T.add(dot[i].x,dot[i].y - dot[i].l,1),
								T.add(dot[i].x,dot[i].y + 1,-1);
		if(dot[i].dir == 3) T.add(dot[i].x + 1,dot[i].y,-1),
								T.add(dot[i].x + 1,dot[i].y + dot[i].l + 1,1);
		if(dot[i].dir == 4) T.add(dot[i].x + 1,dot[i].y + 1,1),
								T.add(dot[i].x + 1 ,dot[i].y - dot[i].l,- 1);
		if(dot[i].dir == 0) ans[i] += T.query(dot[i].x,dot[i].y);
	}
	T.clear();
	for(int i = 1;i <= Q;i++) {
		if(dot[i].dir == 1) T.add(dot[i].x + dot[i].y + dot[i].l + 1,n - dot[i].y + 2,1),
								T.add(dot[i].x + dot[i].y + dot[i].l + 1,n - dot[i].y - dot[i].l + 1,-1);
		if(dot[i].dir == 4) T.add(dot[i].x + dot[i].y - dot[i].l,n - dot[i].y + 1,1),
								T.add(dot[i].x + dot[i].y - dot[i].l,n - dot[i].y + dot[i].l + 2,-1);
		if(dot[i].dir == 0) ans[i] += T.query(dot[i].x + dot[i].y,n - dot[i].y + 1);
	}
	T.clear();
	for(int i = 1;i <= Q;i++) {
		if(dot[i].dir == 2) T.add(dot[i].x - dot[i].y + dot[i].l + n + 1,dot[i].y + 1,1),
								T.add(dot[i].x - dot[i].y + dot[i].l + n + 1,dot[i].y - dot[i].l,-1);
		if(dot[i].dir == 3) T.add(dot[i].x - dot[i].y - dot[i].l + n ,dot[i].y,1),
								T.add(dot[i].x - dot[i].y - dot[i].l + n,dot[i].y + dot[i].l + 1,-1);
		if(dot[i].dir == 0) ans[i] += T.query(dot[i].x - dot[i].y + n,dot[i].y); 
	}
	for(int i = 1;i <= Q;i++) if(dot[i].dir == 0) printf("%d\n",ans[i]);
	return 0;
}
